package com.zt.util;

import com.sun.org.apache.regexp.internal.RE;
import lombok.Data;

import java.awt.*;

@Data
public class ResultVo<T> {
    private Integer code;
    private String msg;
    private  T obj;

    public ResultVo(Integer code, String msg) {
        this.code=code;
        this.msg=msg;
    }
    public ResultVo() {}

    public ResultVo(ApiServiceExceptionEnum dataNotExists) {
        this.code=dataNotExists.getCode();
        this.msg=dataNotExists.getMessage();
    }

    public static ResultVo success(Object object) {
        ResultVo resultVO = new ResultVo(200,"成功");
        resultVO.setObj(object);
        return resultVO;
    }
    public static ResultVo success(Integer code,String msg,Object object) {
        ResultVo resultVO = new ResultVo();
        resultVO.setCode(code);
        resultVO.setMsg(msg);
        resultVO.setObj(object);
        return resultVO;
    }

    public static ResultVo success() {
        return success(null);
    }
    public static ResultVo error(Integer code, String msg) {
        ResultVo resultVO = new ResultVo();
        resultVO.setCode(code);
        resultVO.setMsg(msg);
        return resultVO;
    }
    public static ResultVo error(){
        ResultVo resultVO=new ResultVo();
        resultVO.setCode(0);
        resultVO.setMsg("失败");
        return resultVO;
    }
    public static ResultVo error(Integer code,String msg,Object obj){
        ResultVo resultVO=new ResultVo();
        resultVO.setCode(0);
        resultVO.setMsg(msg);
        resultVO.setObj(obj);
        return resultVO;
    }
    public static ResultVo error(ApiServiceExceptionEnum apiServiceExceptionEnum){
        ResultVo resultVO=new ResultVo();
        resultVO.setCode(apiServiceExceptionEnum.getCode());
        resultVO.setMsg(apiServiceExceptionEnum.getMessage());
        return resultVO;
    }
}
